#include "sound.h"


void sound_init()
{
	buzzer_init();	
}

unsigned char sound_playJingle(unsigned int *time_ms, Jingle jing)
{
	static unsigned char state=0,repeat=0;
	
	if(state>=jing.duration)
	{
		if(repeat>= jing.repeat)
		{
			buzzer_disable();
			state = 0;
			repeat = 0;
			return 0;
		}
		else
		{
			repeat++;
			state = 0;
		}
	}
	else{
		buzzer_enable();
		buzzer_note(jing.notes[state]);
		*time_ms = jing.times_ms[state];
	
		state++;
	}
	
	return 1;
}

